#include "GMCreatedPlayer.h"
#include "Factory.h"
#include "Timer.h"
#include "ClientManager.h"
#include "ClientPlayerManager.h"

#include <iostream>

GMCreatedPlayer::GMCreatedPlayer()
{
	m_id = 0;
}

GMCreatedPlayer::GMCreatedPlayer(int id)
{
	m_id = id;
}

void GMCreatedPlayer::Execute()
{
	std::cout << "Received created player message executed" << std::endl;
	//std::cout << "Timestamp: " << m_timeStamp << std::endl << std::endl;
}

bool GMCreatedPlayer::Read(SocketMessage* sm)
{
	int tempTS = 0;
	sm->ReadInt(&tempTS);
	m_timeStamp = (unsigned int)tempTS;
	std::cout << "created player read timestamp: " << m_timeStamp << std::endl;

	if (sm->ReadInt(&m_id))
	{
		TheCPManager::Instance()->AddClient(m_id, ClientInfo());
		std::cout << "Received created player message, id: " << m_id << std::endl;
		TheClientManager::Instance()->SetID(m_id);

		return true;
	}

	return true;
}

void GMCreatedPlayer::Write(SocketMessage* sm)
{
	sm->WriteString("GMCreatedPlayer");

	m_timeStamp = TheTimer::Instance()->GetTimeMS();

	sm->WriteInt(m_timeStamp);
	sm->WriteInt(m_id);
}